package com.xyh.jdkDemo.queue;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xyh.jdkDemo.queue
 * @类名称：task
 * @创建人：YIHANG.XU
 * @创建时间：2020/8/3011:08 下午
 * @修改人：YIHANG.XU
 * @修改时间：2020/8/3011:08 下午
 * @修改备注：
 * @Copyright
 */
public class Task {
    int priority;
    String name;

    public Task(int priority, String name) {
        this.priority = priority;
        this.name = name;
    }

    public Task() {
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //创建队列顺序格式化
    private static Comparator<Task> taskComparator = new Comparator<Task>() {
        @Override
        public int compare(Task o1, Task o2) {
            if(o1.getPriority()>o2.getPriority()){
                return -1;
            }else if(o1.getPriority()<o2.getPriority()){
                return 1;
            }
            return 0;
        }
    };

    public static void main(String[] args) {
        Queue<Task> tasks = new PriorityQueue<Task>(11, taskComparator);
        tasks.offer(new Task(20, "创建测试"));
        tasks.offer(new Task(10, "፡开始测试"));
        tasks.offer(new Task(100, "测试结果"));
        Task task = tasks.poll();
        while(task!=null){
            System.out.print("任务计划: "+task.getName()
                    +"҅优先级:"+task.getPriority()+"\n");
            task = tasks.poll();
        }
    }


}
